package org.rsbot.script.methods;

import org.rsbot.client.Client;
import org.rsbot.client.RSInterface;
import org.rsbot.script.internal.InputManager;
import org.rsbot.script.util.Timer;
import org.rsbot.script.wrappers.RSCharacter;
import org.rsbot.script.wrappers.RSComponent;
import org.rsbot.script.wrappers.RSObject;
import org.rsbot.script.wrappers.RSTile;

public class Camera extends MethodProvider
{
  Camera(MethodContext paramMethodContext)
  {
    super(paramMethodContext);
  }

  /** @deprecated */
  public void turnToCharacter(RSCharacter paramRSCharacter)
  {
    int i = getCharacterAngle(paramRSCharacter);
    setAngle(i);
  }

  public void turnTo(RSCharacter paramRSCharacter)
  {
    int i = getCharacterAngle(paramRSCharacter);
    setAngle(i);
  }

  /** @deprecated */
  public void turnToCharacter(RSCharacter paramRSCharacter, int paramInt)
  {
    int i = getCharacterAngle(paramRSCharacter);
    i = random(i - paramInt, i + paramInt + 1);
    setAngle(i);
  }

  public void turnTo(RSCharacter paramRSCharacter, int paramInt)
  {
    int i = getCharacterAngle(paramRSCharacter);
    i = random(i - paramInt, i + paramInt + 1);
    setAngle(i);
  }

  /** @deprecated */
  public void turnToObject(RSObject paramRSObject)
  {
    int i = getObjectAngle(paramRSObject);
    setAngle(i);
  }

  public void turnTo(RSObject paramRSObject)
  {
    int i = getObjectAngle(paramRSObject);
    setAngle(i);
  }

  /** @deprecated */
  public void turnToObject(RSObject paramRSObject, int paramInt)
  {
    int i = getObjectAngle(paramRSObject);
    i = random(i - paramInt, i + paramInt + 1);
    setAngle(i);
  }

  public void turnTo(RSObject paramRSObject, int paramInt)
  {
    int i = getObjectAngle(paramRSObject);
    i = random(i - paramInt, i + paramInt + 1);
    setAngle(i);
  }

  /** @deprecated */
  public void turnToTile(RSTile paramRSTile)
  {
    int i = getTileAngle(paramRSTile);
    setAngle(i);
  }

  public void turnTo(RSTile paramRSTile)
  {
    int i = getTileAngle(paramRSTile);
    setAngle(i);
  }

  /** @deprecated */
  public void turnToTile(RSTile paramRSTile, int paramInt)
  {
    int i = getTileAngle(paramRSTile);
    i = random(i - paramInt, i + paramInt + 1);
    setAngle(i);
  }

  public void turnTo(RSTile paramRSTile, int paramInt)
  {
    int i = getTileAngle(paramRSTile);
    i = random(i - paramInt, i + paramInt + 1);
    setAngle(i);
  }

  public boolean setPitch(boolean paramBoolean)
  {
    if (paramBoolean) {
      return setPitch(100);
    }
    return setPitch(0);
  }

  public boolean setPitch(int paramInt)
  {
    int i = getPitch();
    int j = 0;
    if (i == paramInt)
      return true;
    if (i < paramInt) {
      this.methods.inputManager.pressKey('&');
      l = System.currentTimeMillis();
      while ((i < paramInt) && (System.currentTimeMillis() - l < random(50, 100))) {
        if (j != i) {
          l = System.currentTimeMillis();
        }
        j = i;

        sleep(random(5, 10));
        i = getPitch();
      }
      this.methods.inputManager.releaseKey('&');
      return true;
    }
    this.methods.inputManager.pressKey('(');
    long l = System.currentTimeMillis();
    while ((i > paramInt) && (System.currentTimeMillis() - l < random(50, 100))) {
      if (j != i) {
        l = System.currentTimeMillis();
      }
      j = i;
      sleep(random(5, 10));
      i = getPitch();
    }
    this.methods.inputManager.releaseKey('(');
    return true;
  }

  public void moveRandomly(int paramInt)
  {
    Timer localTimer = new Timer(paramInt);
    int i = random(75, 100);
    int j = random(0, 20) < 15 ? 38 : 40;
    int k = random(0, 20) < 5 ? 37 : 39;
    if (random(0, 10) < 8)
      this.methods.inputManager.pressKey((char)j);
    if (random(0, 10) < 8)
      this.methods.inputManager.pressKey((char)k);
    while ((localTimer.isRunning()) && (this.methods.client.getCamPosZ() >= i)) {
      sleep(10);
    }
    this.methods.inputManager.releaseKey((char)j);
    this.methods.inputManager.releaseKey((char)k);
  }

  public void setAngle(int paramInt)
  {
    if (getAngleTo(paramInt) > 5) {
      this.methods.inputManager.pressKey('%');
      while (getAngleTo(paramInt) > 5) {
        sleep(10);
      }
      this.methods.inputManager.releaseKey('%');
    } else if (getAngleTo(paramInt) < -5) {
      this.methods.inputManager.pressKey('\'');
      while (getAngleTo(paramInt) < -5) {
        sleep(10);
      }
      this.methods.inputManager.releaseKey('\'');
    }
  }

  public void setCompass(char paramChar)
  {
    switch (paramChar) {
    case 'n':
      setAngle(359);
      break;
    case 'w':
      setAngle(89);
      break;
    case 's':
      setAngle(179);
      break;
    case 'e':
      setAngle(269);
      break;
    default:
      setAngle(359);
    }
  }

  public void setNorth()
  {
    this.methods.interfaces.getComponent(this.methods.gui.getCompass().getID()).doClick();
  }

  public int getCharacterAngle(RSCharacter paramRSCharacter)
  {
    return getTileAngle(paramRSCharacter.getLocation());
  }

  public int getObjectAngle(RSObject paramRSObject)
  {
    return getTileAngle(paramRSObject.getLocation());
  }

  public int getTileAngle(RSTile paramRSTile)
  {
    int i = (this.methods.calc.angleToTile(paramRSTile) - 90) % 360;
    return i < 0 ? i + 360 : i;
  }

  public int getAngleTo(int paramInt)
  {
    int i = getAngle();
    if (i < paramInt) {
      i += 360;
    }
    int j = i - paramInt;
    if (j > 180) {
      j -= 360;
    }
    return j;
  }

  public int getAngle()
  {
    return (int)(this.methods.client.getCameraYaw() / 45.509999999999998D);
  }

  public int getPitch()
  {
    return (int)((this.methods.client.getCameraPitch() - 1024) / 20.48D);
  }

  public int getX()
  {
    return this.methods.client.getCamPosX();
  }

  public int getY()
  {
    return this.methods.client.getCamPosY();
  }

  public int getZ()
  {
    return this.methods.client.getCamPosZ();
  }
}